import jieba
import wordcloud
import matplotlib.pyplot as plt

if __name__ == "__main__":

    f = open("sanguo.txt", "r", encoding="utf-8")
    t = f.read()
    f.close()
    ls = jieba.lcut(t)
    txt = " ".join(ls)
    w = wordcloud.WordCloud(
        font_path="Arial Unicode.ttf", width=1000, height=700, background_color="white"
    )
    w.generate(txt)

    # print
    plt.imshow(w)
    plt.axis("off")
    w.to_file('generate.png')
    plt.show()